package com.ohos.speechutilsdemo;

import ee.ioc.phon.ohos.speechutils.utils.Define;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.ai.tts.TtsClient;
import ohos.ai.tts.TtsListener;
import ohos.ai.tts.TtsParams;
import ohos.ai.tts.constants.TtsEvent;
import ohos.utils.PacMap;

import org.junit.Test;

import java.util.UUID;

import static org.junit.Assert.assertEquals;

/**
 * 单元测试
 *
 * @since 2021-05-10
 */
public class ExampleOhosTest {
    /**
     * testBundleName方法体
     */
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        Ability ability = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility();
        ability.requestPermissionsFromUser(new String[]{Define.MICROPHONE, Define.SHORTCUTS}, 0);
        TtsClient.getInstance().release();
        /**
         * 监听事件
         */
        TtsListener ttsListener = new TtsListener() {
            @Override
            public void onEvent(int eventType, PacMap pacMap) {
                if (eventType == TtsEvent.CREATE_TTS_CLIENT_SUCCESS) {
                    TtsParams ttsParams = new TtsParams();
                    ttsParams.setDeviceId(UUID.randomUUID().toString());
                    TtsClient.getInstance().init(ttsParams);
                }
            }

            @Override
            public void onStart(String utteranceId) {
            }

            @Override
            public void onProgress(String utteranceId, byte[] audioData, int progress) {
            }

            @Override
            public void onFinish(String utteranceId) {
            }

            @Override
            public void onError(String errorInfo, String s1) {
            }

            @Override
            public void onSpeechStart(String utteranceId) {
            }

            @Override
            public void onSpeechProgressChanged(String utteranceId, int progress) {
            }

            @Override
            public void onSpeechFinish(String utteranceId) {
            }
        };
        TtsClient.getInstance().create(ability, ttsListener);
        TtsClient.getInstance().stopSpeak();
        TtsClient.getInstance().speakLongText("你好", null);
        assertEquals("com.ohos.speechutilsdemo", actualBundleName);
    }
}